//
//  DIYHeader.swift
//  CustomizeCollectionView
//
//  Created by GZOffice_hao on 2019/4/28.
//  Copyright © 2019 VT. All rights reserved.
//

import UIKit

class DIYHeader: UICollectionReusableView {
    
    @IBOutlet private weak var backgroundImageView: UIImageView!
    @IBOutlet private weak var foregroundImageView: UIImageView!
    @IBOutlet private weak var backgroundImageViewHeightLayoutConstraint: NSLayoutConstraint!
    
    private var backgroundImageViewHeight: CGFloat = 0
    private var previousHeight: CGFloat = 0
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        backgroundImageViewHeight = backgroundImageView.bounds.height
    }
    
    
    override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
        if let attributes = layoutAttributes as? DIYLayoutAttributes {
            let height = attributes.frame.height
            if (previousHeight != height) {
                backgroundImageViewHeightLayoutConstraint.constant = backgroundImageViewHeight -  attributes.deltaY
                previousHeight = height
            }
        }
    }
}
